<?php

namespace Modules\Shop\Http\Controllers;
use Illuminate\View\FileViewFinder;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Modules\Shop\Entities\Article;
use Modules\Shop\Entities\TagArticle;
use View;
use App;
class HomeController extends Controller
{
    /**
     * Display a listing of the resource.
     * @return Response
     */
    public function __construct () {
		//获得public下的templates文件夹路径
		$config=\HDModule::config('admin.config.template');
		$path=[public_path ('templates').'/'.$config];
		//改变模板的目录文件夹,在构造函数中将view加载模板的路径改变，指向我们给定的目录
		View::setFinder (new FileViewFinder(App::make ('files'),$path));
	}

	public function index()
    {
        return view('index');
    }
	public function list($id){

    	return view('list',compact('id'));
	}
	public function detail(Article $article){
    	$article->click=$article->click+1;
    	$article->save();
    	return view('detail',compact('article'));
	}
	public function tag($tag_id){
    	$aid=TagArticle::where('tag_id',$tag_id)->pluck('article_id');
    	$articles=Article::whereIn('id',$aid)->orderBy('created_at','desc')->get();
    	return view('tag',compact('articles'));
	}
}
